package io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PwDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos =new FileOutputStream("pw.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入内容，输入exit退出");
        while (true){
            String line = scan.nextLine();
            if ("exit".equals(line)){
                System.out.println("退出成功");
                break;
            }
            pw.println(line);//pw.print(line);不会自动刷新
        }
        pw.close();
    }
}
